﻿@using WsdShop.Model
@{
    Layout = "";
}
<div ng-controller="MyAddressControl">

        <div class="fual_r" ng-repeat="item in List">
            <div class="uai_m">
                <p class="uinp">
                    <span>{{item.Consignee}}</span>
                    <label>{{item.Mobile}}</label>
                </p>
                <p>{{item.Address}}</p>
            </div>
            <div class="uied" >
                <label ng-class="{true:'fuidef isdefault',false:'fuidef'}[item.IsDefault]" ng-click="setDefault(item)">
                    设为默认地址
                </label>

                <a  class="addrdel" ng-click="delAddress(item.Id)">删除</a>
                <a ng-click="editAddress(item.Id);" class="addredit">编辑</a>
            </div>
        </div>
    <button class="fscibtn" style="bottom:60px" ng-click="$state.go('user.index');">返回</button>
    <button class="fscibtn" ng-click="$state.go('user.addressinfo')">新建地址</button>
</div>
<script>
    App.controller('MyAddressControl', [
            '$scope', '$state', '$route', '$http', '$rootScope', "$stateParams",
                function ($scope, $state, $route, $http, $rootScope, $stateParams) {

                    $http.post("/UserCenter/GetMyAddress").then(function (response) {
                        console.log(response.data.data);

                        $scope.List = angular.copy(response.data.data);
                        if ($scope.List == null) {
                            $scope.List = {};
                        }

                    });
                    var tt = function () {
                        $rootScope.WxShare($rootScope.pageTitle(), '优品三悦', location.href, $rootScope.LogoUrl);
                    }

                    setTimeout(tt, 1000)
                    $scope.editAddress = function (id) {
                        $state.go('user.addressinfo', { "Id": id })
                    }

                    $scope.setDefault = function (item)
                    {
                        if (!item.IsDefault)
                        {
                            layer.load(2);
                            $http.post("/UserCenter/SetDefault",{ id: item.Id }).then(function (response) {
                                
                                if (response.data.isSuccess)
                                {
                                    $http.post("/UserCenter/GetMyAddress").then(function (response) {
                                        layer.closeAll('loading');
                                        $scope.List = angular.copy(response.data.data);
                                        if ($scope.List == null) {
                                            $scope.List = {};
                                        }

                                    });
                                }
                                else {
                                    layer.closeAll('loading');
                                    layer.msg(response.data.msg);
                                }

                            });
                        }
                    }

                    $scope.delAddress = function (id)
                    {
                        layer.confirm('确定删除吗？', {
                            btn: ['确定', '取消'] //按钮
                        }, function () {
                            layer.load(2);
                            $http.post("/UserCenter/DelAddress", { id: id }).then(function (response) {
                                
                                if (response.data.isSuccess) {
                                    layer.msg("删除成功");
                                    $http.post("/UserCenter/GetMyAddress").then(function (response) {
                                        layer.closeAll('loading');
                                        $scope.List = angular.copy(response.data.data);
                                        if ($scope.List == null) {
                                            $scope.List = {};
                                        }

                                    });
                                }
                                else {
                                    layer.closeAll('loading');
                                    layer.msg(response.data.msg);
                                }

                            });
                        }, function () {

                        });
                    }

                }
    ]);
</script>